package com.zhuanzhuan.hero.user.enums;

import com.zhuanzhuan.hero.user.vo.IdAndNameVO;
import lombok.Getter;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.*;

/**
 * @ClassName UserAuthTypeEnum
 * @Description
 * @Author hanjunjun
 * @Date 2024/6/27 19:24
 */
@Getter
public enum UserAuthTypeEnum {

    REALNAME(1, "实人认证"),
    ENTERPRISE(2, "企业认证"),
    STORE(3, "门店"),
    RECYCER(4, "回收商"),
    E_MERCHANT(5, "电商平台商户"),
    LARGE_GOODS(6, "大货供应商"),
    DOUYIN_TALENT(7, "抖音达人"),
    //行业抖音大V认证
    DOUYIN_V(8, "抖音大V"),
    //保卖仓商户认证
    BM_WAREHOUSE(9, "保卖仓"),
    //转转已验机2.0商户
    ZHUANZHUAN_MERCHANT(10, "已验机2.0"),
    ;

    private final Integer code;

    private final String name;

    UserAuthTypeEnum(Integer code, String name) {
        this.code = code;
        this.name = name;
    }

    /**
     * 需要运营审核的标认证类型
     */
    private static final List<Integer> MANAGEMENT_AUDIT_AUTH_TYPE_LIST = Arrays.asList(UserAuthTypeEnum.STORE.getCode(),
            UserAuthTypeEnum.RECYCER.getCode(), UserAuthTypeEnum.E_MERCHANT.getCode(), UserAuthTypeEnum.LARGE_GOODS.getCode(),
            UserAuthTypeEnum.DOUYIN_TALENT.getCode(), UserAuthTypeEnum.DOUYIN_V.getCode());

    public static List<Integer> getManagementAuditAuthTypeList() {
        return MANAGEMENT_AUDIT_AUTH_TYPE_LIST;
    }

    private static final Map<Integer, String> CODE_NAME_MAP = new HashMap<>();

    static {
        for (UserAuthTypeEnum anEnum : UserAuthTypeEnum.values()) {
            CODE_NAME_MAP.put(anEnum.getCode(), anEnum.name);
        }
    }

    public static String getNameByCode(Integer code) {
        if (Objects.isNull(code)) {
            throw new IllegalArgumentException();
        }
        return CODE_NAME_MAP.get(code);
    }

    /**
     * 身份认证
     */
    public static List<Integer> identity() {
        return Arrays.asList(STORE.getCode(), RECYCER.getCode(), E_MERCHANT.getCode(), LARGE_GOODS.getCode(), DOUYIN_TALENT.getCode());
    }

    /**
     * 平台认证
     */
    public static List<Integer> platform() {
        return Arrays.asList(REALNAME.getCode(), ENTERPRISE.getCode(), DOUYIN_V.getCode(), BM_WAREHOUSE.getCode(), ZHUANZHUAN_MERCHANT.getCode());
    }

    /**
     * 账号认证; 就是平台认证,不包含实人认证,用于前端展示
     */
    public static List<Integer> account() {
        return Arrays.asList(ENTERPRISE.getCode(),DOUYIN_V.getCode(), BM_WAREHOUSE.getCode(), ZHUANZHUAN_MERCHANT.getCode());
    }


    /**
     * 身份列表
     * @return
     */
    public static List<IdAndNameVO> getIdentityList() {
        return Arrays.stream(values()).filter(x->identity().contains(x.getCode())).map(x->new IdAndNameVO(String.valueOf(x.getCode()), x.getName())).collect(Collectors.toList());
    }

    /**
     * 账号认证
     */
    public static List<IdAndNameVO> getAccountList() {
        return Arrays.stream(values()).filter(x->account().contains(x.getCode())).map(x->new IdAndNameVO(String.valueOf(x.getCode()), x.getName())).collect(Collectors.toList());
    }


}
